package cn.itcast.order.service;


import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import org.example.clients.UserClient;
import org.example.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private UserClient userClient;
//    @Autowired
//    private RestTemplate restTemplate;
//    public Order queryOrderById(Long orderId) {
//        // 1.查询订单
//        Order order = orderMapper.findById(orderId);
//
//        // 2. 利用restTemplate调用商品服务查询商品
//        String url = "http://userservice/user/" + order.getUserId();
//         User user = restTemplate.getForObject(url, User.class);
//        // 3. 设置用户
//        order.setUser(user);
//        // 4.返回
//        return order;
//    }

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);

        // 2. 使用Feign远程调用
        User user = userClient.findById(order.getUserId());
        // 3. 设置用户
        order.setUser(user);
        // 4.返回
        return order;
    }
}
